package org.deadline.model.config;

import flexjson.JSONDeserializer;
import flexjson.JSONSerializer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.persistence.Embeddable;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

@Embeddable
public class Guid {

    @NotNull
    @Size(min = 3, max = 100)
    private String tenentId;

    @NotNull
    @Size(min = 32, max = 32)
    private String uuid;

	public String toString() {
        return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
    }

	public String getTenentId() {
        return this.tenentId;
    }

	public void setTenentId(String tenentId) {
        this.tenentId = tenentId;
    }

	public String getUuid() {
        return this.uuid;
    }

	public void setUuid(String uuid) {
        this.uuid = uuid;
    }

	public String toJson() {
        return new JSONSerializer().exclude("*.class").deepSerialize(this);
    }

	public static Guid fromJsonToGuid(String json) {
        return new JSONDeserializer<Guid>().use(null, Guid.class).deserialize(json);
    }

	public static String toJsonArray(Collection<Guid> collection) {
        return new JSONSerializer().exclude("*.class").deepSerialize(collection);
    }

	public static Collection<Guid> fromJsonArrayToGuids(String json) {
        return new JSONDeserializer<List<Guid>>().use(null, ArrayList.class).use("values", Guid.class).deserialize(json);
    }
}
